package com.leyou.item.mapper;

import com.leyou.item.pojo.Brand;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.additional.idlist.IdListMapper;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

/**
 * @Date 2018/12/12  13:55
 * @Author JIE
 */

public interface BrandMapper extends Mapper<Brand>,IdListMapper<Brand,Long> {

    /**
     * 中间表数据的新增
     * @param cid
     * @param bid
     * @return
     */
    @Insert("INSERT INTO tb_category_brand (category_id, brand_id) VALUES (#{cid},#{bid})")
    int insertCategoryBrand(@Param("cid")Long cid,@Param("bid")Long bid);

    @Delete("DELETE FROM tb_category_brand WHERE brand_id=#{bid}")
    void  deleteCategoryBrand(@Param("bid")Long bid);

    /**
     * 根据cid内连接查询tb_category_brand表与tb_brand表的数据
     * @param cid
     * @return
     */
    @Select("select b.id,b.name,b.image,b.letter  FROM tb_brand b INNER JOIN tb_category_brand cb on b.id=cb.brand_id where cb.category_id=#{cid};")
    List<Brand> selectBrandByCid(@Param("cid")Long cid);
}
